<template>
	<view class="integral" v-if="integralProduct && integralProduct.length">
		<image src="https://qn.mtj.cdydsy.com/user_client/new-version/user-integral-base.png" mode="aspectFill"
			class="image" @click="navigateTo('/subPackages/integral-mall/index')"></image>
		<view class="box u-flex">
			<view class="li u-flex-col" v-for="item in integralProduct" :key="item.id"
				@click="navigateTo(`/subPackages/integral-mall/detail?integral_product_id=${item.id}`)">
				<zero-lazy-load :height="120" imgMode='aspectFill' :borderRadius="4" :image="item.product?.cover_image"
					class="li-img"></zero-lazy-load>
				<view class="li-name">{{item.product?.name}}</view>
				<view class="num">{{item.integral}} 积分</view>
				<view class="li-button">立即兑换</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { computed } from 'vue'
	import { navigateTo } from '@/utils/router.js'
	import useUserStore from '@/store/modules/user.js';

	const userStore = useUserStore();
	const integralProduct = computed(() => userStore.integralProduct.slice(0, 3));
</script>

<style lang="scss" scoped>
	.integral {
		padding: 0 28rpx;
		margin-top: 30rpx;

		.image {
			width: 694rpx;
			height: 270rpx;
			display: block;
		}

		.box {
			padding: 24rpx 48rpx 24rpx 50rpx;
			width: 654rpx;
			background: $base-color-white;
			border-radius: 10rpx;
			margin: -176rpx auto 0;

			.li {
				margin-right: 94rpx;

				.li-img {
					width: 122rpx;
					height: 120rpx;
					display: block;
					border-radius: 4rpx;
				}

				.li-name {
					padding-top: 10rpx;
					width: 122rpx;
					font-family: Source Han Sans CN, Source Han Sans CN;
					font-weight: 400;
					font-size: $font-size-20;
					color: #3E3E3E;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

				.num {
					font-family: Source Han Sans CN, Source Han Sans CN;
					font-weight: 500;
					font-size: $font-size-24;
					color: $base-color;
					text-align: center;
					padding: 10rpx 0;
				}

				.li-button {
					width: 124rpx;
					height: 36rpx;
					line-height: 36rpx;
					text-align: center;
					background: $base-color;
					border-radius: 4rpx;
					font-family: Source Han Sans CN, Source Han Sans CN;
					font-weight: 400;
					font-size: $font-size-20;
					color: $base-color-white;

					&:active {
						opacity: 0.7;
					}
				}
			}

			.li:last-child {
				margin-right: 0;
			}
		}
	}
</style>